<template>
  <div class="bottom-bar-base">
    <div class="bottom-bar">
      <div 
        class="bar-item" 
        :class="{barSelect: barSelect === v.id}"
        v-for="(v, i) in barData" :key="i"
        @click="barClick(v)"
      >
        <i class="iconfont" :class="v.icon" v-if="v.icon"></i>
        <span class="name">{{ v.name }}</span>
      </div>
    </div>
  </div>
</template>
<script setup>
import {
  ref,
  onMounted
} from "vue";
import { useRoute, useRouter } from "vue-router";

const route = useRoute();
const router = useRouter();

const barSelect = ref("");
const barData = ref([
  {
    id: 1,
    name: "主页",
    icon: "icon-shouye",
    path: "/",
  },
  {
    id: 2,
    name: "分类",
    icon: "icon-chaxun",
    path: "/serachList",
  },
  {
    id: 3,
    name: "发现",
    icon: "icon-dianpu",
    path: "/search",
  },
  {
    id: 4,
    name: "购物车",
    icon: "icon-gouwuche",
    path: "/payCard",
  },
  {
    id: 5,
    name: "我的",
    icon: "icon-gerenzhongxin",
    path: "/myInfo",
  },
]);

const barClick = bar => {
  router.push(bar.path);
};

onMounted(() => {
  let data = barData.value.find(v => v.path === route.path);
  if (data) barSelect.value = data.id;
});

</script>
<style lang="scss" scoped>
.bottom-bar-base {
  &::before {
    width: 7.5rem;
    height: 1.25rem;
    display: block;
    content: '';
  }
}
.bottom-bar {
  position: fixed;
  bottom: 0;
  width: 7.5rem;
  padding: 0.25rem;
  background: #08090d;
  color: #fff;
  font-size: 0.2rem;
  display: flex;
  justify-content: space-around;
  align-items: center;
  .bar-item {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    .iconfont {
      margin: 0 0 0.1rem;
      color: #fff;
      font-size: 0.35rem;
    }
    &.barSelect {
      color: #b49bff;
      text-shadow: 0 0 0.02rem #b49bff;
      font-weight: bold;
      .iconfont {
        color: #b49bff;
        text-shadow: 0 0 0.02rem #b49bff;
        font-weight: bold;
      }
    }
  }
}
</style>